package org.net.cms.controller.app.student;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.net.cms.config.Result;
import org.net.cms.service.student.StudentService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/student")
@Tag(name = "APP - 学生")
public class AppStudentController {
    // 接口测试无误

    @Resource
    private StudentService studentService;

    // 查看当前家长的孩子列表
    @GetMapping("/all")
    @Operation(summary = "查看当前家长的孩子列表")
    public Result findStudentAll() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        String phone = userDetails.getUsername();
        return Result.success(studentService.findMyStudents(studentService.getParentId(phone)));
    }

    // 查看某个孩子的详情信息
    @GetMapping("/get")
    @Operation(summary = "查看某个孩子的详情信息")
    @Parameter(name = "id", description = "学生id", required = true)
    public Result findStudentById(int id) {
        return Result.success(studentService.findById(id));
    }

}
